<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>登录页面 - Nkuvr 后台管理</title>

    <meta name="author" content="yinqi">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <style>
        .lyear-wrapper {
            position: relative;
        }

        .lyear-login {
            display: flex !important;
            min-height: 100vh;
            align-items: center !important;
            justify-content: center !important;
        }

        .login-center {
            background: #fff;
            min-width: 38.25rem;
            padding: 2.14286em 3.57143em;
            border-radius: 5px;
            margin: 2.85714em 0;
        }

        .login-header {
            margin-bottom: 1.5rem !important;
        }

        .login-center .has-feedback.feedback-left .form-control {
            padding-left: 38px;
            padding-right: 12px;
        }

        .login-center .has-feedback.feedback-left .form-control-feedback {
            left: 0;
            right: auto;
            width: 38px;
            height: 38px;
            line-height: 38px;
            z-index: 4;
            color: #dcdcdc;
        }

        .login-center .has-feedback.feedback-left.row .form-control-feedback {
            left: 15px;
        }
    </style>
    <link rel="stylesheet" href="../static/css/materialdesignicons.min.css">
</head>

<body>
<div class="row lyear-wrapper">
    <div class="lyear-login">
        <div class="login-center">
            <div class="login-header text-center">
                <a href="/"> <img alt="light year admin" src="images/logo-sidebar.png"> </a>
            </div>
            <form>
                <div class="form-group has-feedback feedback-left">
                    <input type="text" placeholder="请输入学号" class="form-control" name="studentNumber"
                           id="studentNumber"/>
                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left">
                    <input type="password" placeholder="请输入密码" class="form-control" id="password" name="password"/>
                    <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group">
                    <a class="btn btn-block btn-primary" href="javascript:void(0);" onclick="return doLogin();">立即登录
                    </a>
                </div>
            </form>
            没有账号？<a href="/register">点击注册</a>
            <hr>
            <footer class="col-sm-12 text-center">
                <p class="m-b-0">Copyright © 2020 Nkuvr.com .All right reserved</p>
            </footer>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script src="layer/layer.js"></script>
<script type="text/javascript">
    function doLogin() {
        var studentNumber = $("#studentNumber").val();
        var password = $("#password").val();
        var loadingIndex = null;
        if (studentNumber === "") {
            layer.msg("学号不能为空，请输入!", {time: 1000, icon: 5, shift: 6});
            return;
        }
        if (!studentNumber.match(/\d{8}$/)) {
            layer.msg("请输入正确的学号!", {time: 1000, icon: 5, shift: 6});
            return;
        }
        if (password === "") {
            layer.msg("密码不能为空，请输入!", {time: 1000, icon: 5, shift: 6});
            return;
        }
        $.ajax({
            type: "post",
            url: "/doLogin",
            async: false,
            dataType: "json",
            data: {
                "studentNumber": studentNumber,
                "password": password
            },
            beforeSend: function () {
                loadingIndex = layer.msg("处理中", {icon: 16});
            },
            success: function (result) {
                layer.close(loadingIndex);
                if (result.success) {
                    layer.msg("登录成功", {time: 1000, icon: 6})
                    window.location.href = "/user/index";
                } else {
                    layer.msg("学号或密码错误，请重新输入", {time: 1000, icon: 5, shift: 6});
                }
            }
        });
        return false;
    }
</script>
</body>
</html>